home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / WANDR330.ZIP / SRC / FALL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-05  |  10.7 KB  |  368 lines

  1. #include "wand_head.h"
  2.  
  3. extern void draw_symbol();
  4. extern int debug_disp;
  5. extern char screen[NOOFROWS][ROWLEN+1];
  6. extern WINDOW *win;
  7. extern int pause1;
  8. extern int recording;
  9.  
  10. int moving = 0;    /* so that bombs explode only if something *hits* them */
  11.  
  12. int check(mx, my, x, y, dx, dy, sx, sy, howdead)
  13. /* check for any falling caused by something moving out of x,y along
  14.    vector dx,dy. All the others are constant and should really have
  15.    been global...                             */
  16. int x, y, sx, sy, dx, dy, *mx, *my;
  17. char howdead[25];
  18. {
  19.     int ret = 0;
  20.     if(recording != 2) flushinp(); /* type ahead gets in the way */
  21.     ret += fall(mx,my,x,y,sx,sy,howdead);
  22.     ret += fall(mx,my,x-dx,y-dy,sx,sy,howdead);
  23.     ret += fall(mx,my,x-dy,y-dx,sx,sy,howdead);
  24.     ret += fall(mx,my,x+dy,y+dx,sx,sy,howdead);
  25.     ret += fall(mx,my,x-dx-dy,y-dy-dx,sx,sy,howdead);
  26.     ret += fall(mx,my,x-dx+dy,y-dy+dx,sx,sy,howdead);
  27.     return ret;
  28. }
  29.  
  30. int fall(mx, my, x, y, sx, sy, howdead)    /* recursive function for falling */
  31.                     /* boulders and arrows */
  32. int  x, y, sx, sy, *mx, *my;
  33. char howdead[25];
  34. {
  35.     int nx = x, nxu = x, nyl = y, nyr = y, ny = y, retval = 0;
  36.     if ((y > (NOOFROWS-1)) || (y < 0) || (x < 0) || (x > (ROWLEN-1)))
  37.     return(0);
  38.     if (screen[y][x] == '~') {
  39.     if (screen[y-1][x] == ' ') fall(mx,my,x,y-1,sx,sy,howdead);
  40.     if (screen[y+1][x] == ' ') fall(mx,my,x,y+1,sx,sy,howdead);
  41.     if (screen[y][x-1] == ' ') fall(mx,my,x-1,y,sx,sy,howdead);
  42.     if (screen[y][x+1] == ' ') fall(mx,my,x+1,y,sx,sy,howdead);
  43.     }
  44.     if ((screen[y][x] != 'O') && (screen[y][x] != ' ') &&
  45.     (screen[y][x] != 'M') && (screen[y][x] !='\\') &&
  46.     (screen[y][x] != '/') && (screen[y][x] != '@') &&
  47.     (screen[y][x] != '^') && (screen[y][x] != 'B'))
  48.     return(0);
  49.     if ((screen[y][x] == 'B') && (moving == 0))
  50.     return 0;
  51.     if (screen[y][x] == 'O') {
  52.     if ((screen[y][x-1] == ' ') && (screen[y-1][x-1] == ' '))
  53.         nx--;
  54.     else {
  55.         if ((screen[y][x+1] == ' ') && (screen[y-1][x+1] == ' '))
  56.         nx++;
  57.         else
  58.         nx = -1;
  59.     }
  60.     if ((screen[y][x-1] == ' ') && (screen[y+1][x-1] == ' '))
  61.         nxu--;
  62.     else {
  63.         if ((screen[y][x+1] == ' ') && (screen[y+1][x+1] == ' '))
  64.         nxu++;
  65.         else
  66.         nxu = -1;
  67.     }
  68.     if ((screen[y-1][x] == ' ') && (screen[y-1][x+1] == ' '))
  69.         nyr--;
  70.     else {
  71.         if ((screen[y+1][x] == ' ') && (screen[y+1][x+1] == ' '))
  72.         nyr++;
  73.         else
  74.         nyr = -1;
  75.     }
  76.     if ((screen[y-1][x] == ' ') && (screen[y-1][x-1] == ' '))
  77.         nyl--;
  78.     else {
  79.         if ((screen[y+1][x] == ' ') && (screen[y+1][x-1] == ' '))
  80.         nyl++;
  81.         else
  82.         nyl = -1;
  83.     }
  84.     }
  85.     if (screen[y][x] == '\\') {
  86.     if (screen[y-1][++nx] != ' ')
  87.         nx = -1;
  88.     if (screen[y+1][--nxu] != ' ')
  89.         nxu = -1;
  90.     if (screen[--nyr][x+1] != ' ')
  91.         nyr = -1;
  92.     if (screen[++nyl][x-1] != ' ')
  93.         nyl = -1;
  94.     }
  95.     if (screen[y][x] == '/') {
  96.     if (screen[y-1][--nx] != ' ')
  97.         nx = -1;
  98.     if (screen[y+1][++nxu] != ' ')
  99.         nxu = -1;
  100.     if (screen[++nyr][x+1] != ' ')
  101.         nyr = -1;
  102.     if (screen[--nyl][x-1] != ' ')
  103.         nyl = -1;
  104.     }
  105.     if ((screen[y][nx] != ' ') && (screen[y][nx] != 'M') &&
  106.     (screen[y][nx] != 'B'))
  107.     nx = -1;
  108.     if ((screen[y-1][x] == 'O') && (nx >= 0) && (y > 0)) { /* boulder falls ? */
  109.     moving = 1;
  110.     screen[y-1][x] = ' ';
  111.     if (screen[y][nx] == '@') {
  112.         strcpy(howdead,"a falling boulder");
  113.         retval = 1;
  114.     }
  115.     if (screen[y][nx] == 'M') {
  116.         *mx = *my = -2;
  117.         screen[y][nx] = ' ';
  118.     }
  119.     if (screen[y][nx] == 'B') {
  120.         retval = bang(nx,y,mx,my,sx,sy,howdead);
  121.         return retval;
  122.     }
  123.     screen[y][nx] = 'O';
  124.     if (!debug_disp) {
  125.         if ((y < (sy+5)) && (y > (sy-3)) && (x > (sx-6)) && (x < (sx+6)))
  126.         draw_symbol((x-sx+5)*3,(y-sy+2)*2,' ');
  127.         if ((y < (sy+4)) && (y>(sy-4)) && (nx>(sx-6)) && (nx<(sx+6)))
  128.         draw_symbol((nx-sx+5)*3,(y-sy+3)*2,'O');
  129.     } else {
  130.         draw_object(y,x+1,' ');
  131.         draw_object(y+1,nx+1,'O');
  132.     }
  133.     wrefresh(win);
  134.     delay(pause1);
  135.     retval += fall(mx,my,nx ,y+1,sx,sy,howdead);
  136.     moving = 0;
  137.     retval += check(mx,my,x,y-1,0,1,sx,sy,howdead);
  138.     if (y + 1 < NOOFROWS && screen[y+1][nx] == '@') {
  139.         strcpy(howdead,"a falling boulder");
  140.         return(1);
  141.         }
  142.     if (y + 1 < NOOFROWS && screen[y+1][nx] == 'M') {
  143.         *mx = *my = -2;
  144.         screen[y+1][nx] = ' ';
  145.     }
  146.     }
  147.     if ((screen[nyr][x] != '^') && (screen[nyr][x] != ' ') &&
  148.     (screen[nyr][x] != 'M') && (screen[nyr][x] != 'B'))
  149.     nyr = -1;
  150.     if ((screen[y][x+1] == '<') &&
  151.     (nyr>=0)&&(x+1<ROWLEN)) {    /* arrow moves ( < ) ? */
  152.     moving = 1;
  153.     screen[y][x+1] = ' ';
  154.     if (screen[nyr][x] == '@') {
  155.         strcpy(howdead,"a speeding arrow");
  156.         retval = 1;
  157.     }
  158.     if (screen[nyr][x] == 'M') {
  159.         *mx = *my = -2;
  160.         screen[nyr][x] = ' ';
  161.     }
  162.     if (screen[nyr][x] == 'B') {
  163.         retval = bang(x,nyr,mx,my,sx,sy,howdead);
  164.         return retval;
  165.     }
  166.     screen[nyr][x] = '<';
  167.     if (!debug_disp) {
  168.         if ((y < (sy+4)) && (y > (sy-4)) && (x < (sx+5)) &&
  169.         (x > (sx-7)))
  170.         draw_symbol((x-sx+6)*3,(y-sy+3)*2,' ');
  171.         if ((nyr < (sy+4)) && (nyr > (sy-4)) && (x < (sx+6)) &&
  172.         (x>(sx-6)))
  173.         draw_symbol((x-sx+5)*3,(nyr-sy+3)*2,'<');
  174.     } else {
  175.         draw_object(y+1,x+2,' ');
  176.         draw_object(nyr+1,x+1,'<');
  177.     }
  178.     wrefresh(win);
  179.     delay(pause1);
  180.     retval += fall(mx,my,x-1,nyr,sx,sy,howdead);
  181.     moving = 0;
  182.     retval += check(mx,my,x+1,y,-1,0,sx,sy,howdead);
  183.     if (screen[nyr][x-1] == '@') {
  184.         strcpy(howdead,"a speeding arrow");
  185.         return(1);
  186.     }
  187.     if (screen[nyr][x-1] == 'M') {
  188.         *mx = *my = -2;
  189.         screen[nyr][x-1] = ' ';
  190.     }
  191.     }
  192.     if ((screen[nyl][x] != ' ') && (screen[nyl][x] != '^') &&
  193.     (screen[nyl][x] != 'M') && (screen[nyl][x] != 'B'))
  194.     nyl = -1;
  195.     if ((screen[y][x-1] == '>') && (nyl >= 0) &&
  196.     (x > 0)) {    /* arrow moves ( > ) ? */
  197.     moving = 1;
  198.     screen[y][x-1] = ' ';
  199.     if (screen[nyl][x] == '@') {
  200.         strcpy(howdead,"a speeding arrow");
  201.         retval = 1;
  202.         }
  203.     if (screen[nyl][x] == 'M') {
  204.         *mx = *my = -2;
  205.         screen[nyl][x] = ' ';
  206.         }
  207.     if (screen[nyr][x] == 'B') {
  208.         retval = bang(x,nyr,mx,my,sx,sy,howdead);
  209.         return retval;
  210.     }
  211.     screen[nyl][x] = '>';
  212.     if (!debug_disp) {
  213.         if ((y < (sy+4)) && (y > (sy-4)) && (x < (sx+7)) && (x > (sx-5)))
  214.         draw_symbol((x-sx+4)*3,(y-sy+3)*2,' ');
  215.         if ((nyl < (sy+4)) && (nyl > (sy-4)) && (x < (sx+6)) &&
  216.         (x > (sx-6)))
  217.         draw_symbol((x-sx+5)*3,(nyl-sy+3)*2,'>');
  218.     } else {
  219.         draw_object(y+1,x,' ');
  220.         draw_object(nyl+1,x+1,'>');
  221.     }
  222.     wrefresh(win);
  223.     delay(pause1);
  224.     retval += fall(mx,my,x+1,nyl,sx,sy,howdead);
  225.     moving = 0;
  226.     retval += check(mx,my,x-1,y,1,0,sx,sy,howdead);
  227.     if (screen[nyl][x+1] == '@') {
  228.         strcpy(howdead,"a speeding arrow");
  229.         return(1);
  230.     }
  231.     if (screen[nyl][x+1] == 'M') {
  232.         *mx = *my = -2;
  233.         screen[nyl][x+1] = ' ';
  234.     }
  235.     }
  236.  
  237.     if (screen[y][nxu] != ' ')
  238.     nxu = -1;
  239.     if ((screen[y+1][x] == '^') && (nxu >= 0) && (y < NOOFROWS) &&
  240.     (screen[y][x] != '^')&&(screen[y][x] != 'B')) {    /* balloon rises? */
  241.     screen[y+1][x] = ' ';
  242.     screen[y][nxu] = '^';
  243.     if (!debug_disp) {
  244.         if ((y < (sy+3)) && (y > (sy-5)) && (x > (sx-6)) && (x < (sx+6)))
  245.         draw_symbol((x-sx+5)*3,(y-sy+4)*2,' ');
  246.         if ((y < (sy+4)) && (y > (sy-4)) && (nxu > (sx-6)) &&
  247.         (nxu < (sx+6)))
  248.         draw_symbol((nxu-sx+5)*3,(y-sy+3)*2,'^');
  249.     } else {
  250.         draw_object(y+2,x+1,' ');
  251.         draw_object(y+1,nxu+1,'^');
  252.     }
  253.     wrefresh(win);
  254.     delay(pause1);
  255.     retval += fall(mx,my,nxu ,y-1,sx,sy,howdead);
  256.     retval += check(mx,my,x,y+1,0,-1,sx,sy,howdead);
  257.     }
  258.  
  259.     nx = x; ny = y;
  260.  
  261.     if (screen[y][x] == ' ') {     /* thingy moves? */
  262.     if ((y > 1) && (screen[y-1][x] == '~') && (screen[y-2][x] == 'O'))
  263.         /* boulder pushes */
  264.         ny--;
  265.     else if ((x > 1) && (screen[y][x-1] == '~') && (screen[y][x-2] == '>'))
  266.         /* arrow pushes */
  267.         nx--;
  268.     else if ((x < (ROWLEN-1)) && (screen[y][x+1] == '~') &&
  269.         (screen[y][x+2] == '<'))
  270.         /* arrow pushes */
  271.         nx++;
  272.     else if ((y < (NOOFROWS-1)) && (screen[y+1][x] == '~') &&
  273.         (screen[y+2][x] == '^'))
  274.          /* balloon pushes */
  275.         ny++;
  276.     }
  277.  
  278.     if ((x != nx) || (y != ny)) {
  279.     screen[y][x] = '~';
  280.     screen[ny][nx] = screen[2*ny-y][2*nx-x];
  281.     screen[2*ny-y][2*nx-x] = ' ';
  282.     if (!debug_disp) {
  283.         if (((2*ny-y) < (sy+4)) && ((2*ny-y) > (sy-4))
  284.         && ((2*nx-x) > (sx-6)) && ((2*nx-x) < (sx+6)))
  285.         draw_symbol((2*nx-x-sx+5)*3,(2*ny-y-sy+3)*2,' ');
  286.         if ((y < (sy+4)) && (y > (sy-4)) && (x > (sx-6)) &&
  287.         (x < (sx+6)))
  288.         draw_symbol((x-sx+5)*3,(y-sy+3)*2,'~');
  289.         if ((ny < (sy+4)) && (ny > (sy-4)) && (nx > (sx-6)) &&
  290.         (nx < (sx+6)))
  291.         draw_symbol((nx-sx+5)*3,(ny-sy+3)*2,screen[ny][nx]);
  292.     } else {
  293.         draw_object(ny*2-y+1,nx*2-x+1,' ');
  294.         draw_object(ny+1,nx+1,screen[ny][nx]);
  295.         draw_object(y+1,x+1,'~');
  296.     }
  297.     wrefresh(win);
  298.     delay(pause1);
  299.     retval += fall(mx,my,2*x-nx,2*y-ny,sx,sy,howdead);
  300.     retval += check(mx,my,2*nx-x,2*ny-y,nx-x,ny-y,sx,sy,howdead);
  301.     }
  302.  
  303.     if (retval > 0)
  304.     return(1);
  305.     return(0);
  306. }
  307.  
  308. int bang(x, y, mx, my, sx, sy, howdead)    /* explosion centre x,y */
  309. int x, y, sx, sy, *mx, *my;
  310. char *howdead;
  311. {
  312.     int retval = 0;
  313.     int ba, bb;    /* abbrevs for 'bang index a' and 'bang index b' :-) */
  314.     int gottim = 0;
  315.  
  316.     screen[y][x] = ' ';
  317. /* fill with bangs */
  318.     for (ba = -1; ba < 2; ba++)
  319.     for (bb = -1; bb < 2; bb++) {
  320.         if (screen[y+ba][x+bb] == '#') continue; /* rock indestructable */
  321.         if (screen[y+ba][x+bb] == '@') gottim = 1;
  322.         if (screen[y+ba][x+bb] == 'M') *mx = *my = -2; /* kill monster */
  323.         if (screen[y+ba][x+bb] == 'B')
  324.         gottim += bang(x+bb,y+ba,mx,my,sx,sy,howdead);
  325.         screen[y+ba][x+bb] = ' ';
  326.         if (!debug_disp) {
  327.         if (((y+ba) < (sy+4)) && ((y+ba) > (sy-4)) &&
  328.         ((x+bb) > (sx-6)) && ((x+bb) < (sx+6)) && (y+ba >= 0) &&
  329.         (x +bb >= 0) && ((x+bb) < ROWLEN) && ((y+ba) < NOOFROWS))
  330.         draw_symbol((x+bb-sx+5)*3,(y+ba-sy+3)*2,'%');
  331.         } else {
  332.         if (((x+bb) > -1) && ((y+ba) > -1) &&
  333.             ((x+bb) < ROWLEN) && ((y+ba) < NOOFROWS)) {
  334.               draw_object(y+ba+1,x+bb+1,'%');
  335.                   }
  336.     }
  337.     }
  338.     wrefresh(win);
  339.     if (gottim) {
  340.     strcpy(howdead,"an exploding bomb");
  341.     return 1;
  342.     }
  343. /* erase it all */
  344.     for (ba = -1; ba < 2; ba++)
  345.     for (bb = -1; bb < 2; bb++) {
  346.         if (screen[y+ba][x+bb] == '#') continue;
  347.         if (!debug_disp) {
  348.         if (((y+ba) < (sy+4)) && ((y+ba) > (sy-4)) &&
  349.             ((x+bb) > (sx-6)) && ((x+bb) < (sx+6)) &&
  350.             (y+ba > -1) && (x+bb > -1) &&
  351.             ((x+bb) < ROWLEN) && ((y+ba) < NOOFROWS))
  352.             draw_symbol((x+bb-sx+5)*3,(y+ba-sy+3)*2,' ');
  353.         } else {
  354.             if (((x+bb) > -1) && ((y+ba) > -1) &&
  355.             ((x+bb) < ROWLEN) && ((y+ba) < NOOFROWS)) {
  356.              draw_object(y+ba+1,x+bb+1,' ');
  357.         }
  358.         }
  359.     }
  360.  
  361. /* make all the necessary falling */
  362.     retval = check(mx,my,x-1,y-1,1,0,sx,sy,howdead);
  363.     retval += check(mx,my,x-1,y+1,0,-1,sx,sy,howdead);
  364.     retval += check(mx,my,x+1,y-1,0,1,sx,sy,howdead);
  365.     retval += check(mx,my,x+1,y+1,-1,0,sx,sy,howdead);
  366.     return retval;
  367. }
  368.